import demoBlockContainers from './common/containers.js';
import renderDemoBlock from './common/render';
import { createSfcRegexp, TAG_NAME_TEMPLATE } from '@mdit-vue/plugin-sfc';
const sfcRegexp = createSfcRegexp({ customBlocks: [TAG_NAME_TEMPLATE] });
export const markdownContainers = (options) => {
	return {
		name: 'markdown-containers',
		extendsMarkdown: (md) => {
			const { render } = md;
			const render$1 = render.bind(md);
			md.render = (src, env) => {
				let result = render$1(src, env);
				const { template, script } = renderDemoBlock(result);
				const templateSfcBlock = `<template>${template}</template>`.match(sfcRegexp)?.groups;
				const scriptSfcBlock = script?.match(sfcRegexp)?.groups;
				env.sfcBlocks.template = templateSfcBlock || null;
				env.sfcBlocks.template = templateSfcBlock || null;
				env.sfcBlocks.script = scriptSfcBlock;
				return template;
			};
			md.use(demoBlockContainers);
			md.linkify.set({ fuzzyEmail: false });
		},
	};
};
